﻿

using Demo.Admin.Application.Contracts.Users;
using Demo.Admin.Application.Contracts.Users.Dto;
using Volo.Abp.Application.Dtos;
using Volo.Abp.Application.Services;
using Volo.Abp.Identity;

namespace Demo.Admin.Application.Users;

public class  AdminUserAppService : ApplicationService, IAdminUserAppService
{
    private readonly IIdentityUserAppService _identityUserAppService;

    public AdminUserAppService(IIdentityUserAppService identityUserAppService)
    {
        _identityUserAppService = identityUserAppService;
    }

    public async Task<bool> CreateAsync(AdminUserCreateDto input)
    {
        var user = ObjectMapper.Map<AdminUserCreateDto, IdentityUserCreateDto>(input);
        var ret = await _identityUserAppService.CreateAsync(user);
        return true;
    }

    /// <summary>
    /// 分页获取用户列表
    /// </summary>
    /// <param name="input"></param>
    /// <returns></returns>
    /// <exception cref="NotImplementedException"></exception>
    public async Task<PagedResultDto<AdminUserDto>> GetListAsync(PagedAndSortedResultRequestDto input)
    {
        var users = await _identityUserAppService.GetListAsync(new GetIdentityUsersInput
        {
            Sorting = input.Sorting,
            MaxResultCount = input.MaxResultCount,
            SkipCount = input.SkipCount
        });
        return new PagedResultDto<AdminUserDto>()
        {
            TotalCount = users.TotalCount,
            Items = ObjectMapper.Map<IReadOnlyList<IdentityUserDto>, List<AdminUserDto>>(users.Items)
        };

    }
}